<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>梧桐的学习日记 - 你的美好等我去发现</title><meta name="author" content="梧桐影下月光卧"><meta name="copyright" content="梧桐影下月光卧"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="分享个人学习路上的小知识">
<meta property="og:type" content="website">
<meta property="og:title" content="梧桐的学习日记">
<meta property="og:url" content="https://acwy.fun/page/3/index.html">
<meta property="og:site_name" content="梧桐的学习日记">
<meta property="og:description" content="分享个人学习路上的小知识">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://acwy.fun/img/logo.png">
<meta property="article:author" content="梧桐影下月光卧">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://acwy.fun/img/logo.png"><link rel="shortcut icon" href="/img/logo.png"><link rel="canonical" href="https://acwy.fun/page/3/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '梧桐的学习日记',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2024-05-05 21:13:51'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js/themes/blue/pace-theme-minimal.min.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/logo.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 目录</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page fixed" id="page-header" style="background-image: url('/img/top_img.jpeg')"><nav id="nav"><span id="blog-info"><a href="/" title="梧桐的学习日记"><span class="site-name">梧桐的学习日记</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 目录</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">梧桐的学习日记</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/hexo-Butterfly-1-%E5%85%A8%E5%B1%80%E8%AE%BE%E7%BD%AE(%E5%AE%89%E8%A3%85%E3%80%81%E6%A0%87%E9%A2%98%E3%80%81%E8%8F%9C%E5%8D%95%E3%80%81%E5%9B%BE%E6%A0%87%E3%80%81%E9%A1%B6%E9%83%A8%E3%80%81%E9%A1%B5%E8%84%9A%E3%80%81%E4%BE%A7%E8%BE%B9%E6%A0%8F%E3%80%81%E5%9B%BE%E7%89%87%E8%AE%BE%E7%BD%AE)/" title="hexo-Butterfly-全局设置(安装、标题、菜单、图标、顶部、页脚、侧边栏、图片设置)"><img class="post-bg" src= "" data-lazy-src="https://pic1.zhimg.com/v2-f5ca1150bf22dd77e636b0e2fced6d1c_1440w.jpg?source=172ae18b" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="hexo-Butterfly-全局设置(安装、标题、菜单、图标、顶部、页脚、侧边栏、图片设置)"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/hexo-Butterfly-1-%E5%85%A8%E5%B1%80%E8%AE%BE%E7%BD%AE(%E5%AE%89%E8%A3%85%E3%80%81%E6%A0%87%E9%A2%98%E3%80%81%E8%8F%9C%E5%8D%95%E3%80%81%E5%9B%BE%E6%A0%87%E3%80%81%E9%A1%B6%E9%83%A8%E3%80%81%E9%A1%B5%E8%84%9A%E3%80%81%E4%BE%A7%E8%BE%B9%E6%A0%8F%E3%80%81%E5%9B%BE%E7%89%87%E8%AE%BE%E7%BD%AE)/" title="hexo-Butterfly-全局设置(安装、标题、菜单、图标、顶部、页脚、侧边栏、图片设置)">hexo-Butterfly-全局设置(安装、标题、菜单、图标、顶部、页脚、侧边栏、图片设置)</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T12:52:23.000Z" title="发表于 2023-04-10 20:52:23">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/hexo/">hexo</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/hexo-Butterfly-%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2/">hexo-Butterfly - 静态博客</a></span></div><div class="content">Butterfly安装1git clone -b master https://gitee.com/immyw/hexo-theme-butterfly.git
Butterfly主题应用在hexo里的_config.yml设置theme: Butterfly
全局设置（标题）网站资料、语言_config.yml：title、subject等配置 default(en) zh-CN (简体中文) zh-TW (繁体中文)
菜单_config.butterfly.yml：
菜单名： 路径 || 图标 || hide    子菜单： 路径 || 图标默认子目录是展开的，如果你想要隐藏，在子目录里添加 hide 

1234Categories: /categories/ || fas fa-folder-openList||fas fa-list || hide:  Music: /music/ || fas fa-music  Movie: /movies/ || fas fa-video
导航栏1234nav:  logo: #image  display_title: true  f ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/hexo-%E5%AE%89%E8%A3%85%E5%8F%91%E8%A1%8C/" title="hexo-安装发行"><img class="post-bg" src= "" data-lazy-src="https://pic1.zhimg.com/v2-f5ca1150bf22dd77e636b0e2fced6d1c_1440w.jpg?source=172ae18b" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="hexo-安装发行"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/hexo-%E5%AE%89%E8%A3%85%E5%8F%91%E8%A1%8C/" title="hexo-安装发行">hexo-安装发行</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T12:50:23.000Z" title="发表于 2023-04-10 20:50:23">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/hexo/">hexo</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2/">静态博客</a></span></div><div class="content">
安装1npm install hexo-cli -g # 全局
安装以后，可以使用以下两种方式执行 Hexo：npx hexo &lt;command&gt;将 Hexo 所在的目录下的 node_modules 添加到环境变量之中即可直接使用 hexo &lt;command&gt;
建站123hexo init &lt;folder&gt;cd &lt;folder&gt;npm install
网站配置：_config.yml
source资源文件夹，放置图片等
运行：hexo server 简写hexo s
清除缓存文件 (db.json) 和已生成的静态文件 (public) hexo clean
打包(g)部署(d) hexo g -d

</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/%E9%AB%98%E6%80%A7%E8%83%BD%E7%88%AC%E8%99%AB1(%E7%BA%BF%E7%A8%8B%E6%B1%A0)/" title="4.2 高性能爬虫(线程池)"><img class="post-bg" src= "" data-lazy-src="https://img1.baidu.com/it/u=896388663,4005432497&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=800&amp;h=320" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="4.2 高性能爬虫(线程池)"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/%E9%AB%98%E6%80%A7%E8%83%BD%E7%88%AC%E8%99%AB1(%E7%BA%BF%E7%A8%8B%E6%B1%A0)/" title="4.2 高性能爬虫(线程池)">4.2 高性能爬虫(线程池)</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T07:56:23.000Z" title="发表于 2023-04-10 15:56:23">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%BA%BF%E7%A8%8B/">线程</a></span></div><div class="content">线程池基本使用原则: 线程池处理的是阻塞且耗时的操作
12345678# 导入线程池模块对应的类from multiprocessing.dummy import Pool# 实例化一个线程池对象,开启4个线程对象pool = Pool(4)# 将列表中每个元素传递给get_content处理# 参数: 阻塞的函数,参数# 返回: 每个返回值组成的列表page_contets = pool.map(get_content, urls)

实例1: (梨视频爬取)12345678910111213141516171819202122232425262728293031# ...引入对应包# ...请求页面数据tree = etree.HTML(page_text)li_list = tree.xpath(&#x27;//url[@id=&quot;listvideoListUl&quot;]/li&#x27;)urls = []for li in li_list:	# 获取每个视频的链接和名字	detail_url = &#x27;https://www.pearvideo.com&#x ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/%E9%AB%98%E6%80%A7%E8%83%BD%E7%88%AC%E8%99%AB(%E6%A6%82%E5%BF%B5)/" title="4. 高性能爬虫概念1"><img class="post-bg" src= "" data-lazy-src="https://img1.baidu.com/it/u=896388663,4005432497&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=800&amp;h=320" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="4. 高性能爬虫概念1"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/%E9%AB%98%E6%80%A7%E8%83%BD%E7%88%AC%E8%99%AB(%E6%A6%82%E5%BF%B5)/" title="4. 高性能爬虫概念1">4. 高性能爬虫概念1</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T07:55:23.000Z" title="发表于 2023-04-10 15:55:23">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%BA%BF%E7%A8%8B/">线程</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E8%BF%9B%E7%A8%8B/">进程</a></span></div><div class="content">高性能异步爬虫目的: 在爬虫中使用异步实现高性能的数据爬取
普通请求(单线程串行方式执行)循环请求会堵塞后一个请求
12345urls = [&#x27;http://xxxx.rar&#x27;,&#x27;http://xxxx.rar&#x27;,&#x27;http://xxxx.rar&#x27;]# 单线程请求爬取for url in urls:	content = get_content(url)	parse_content(content)

异步一个进程有个多个线程

多线程,多进程(不推荐)

好处: 可以为相关堵塞的操作单独开启线程/进程,阻塞操作就可以异步执行
弊端: 无法无限的开启多线程/多进程


线程池/进程池(适当使用)

好处: 可以降低系统对进程/线程创建和销毁的频率,从而很好降低系统开销
弊端: 池中进程/线程数量也有上限


单线程+异步协程(推荐):python3.4以上才有的

event_loop: 事件循环
相当于一个无限循环,可以把一些函数注册到这个循环上,当满足某种条件,函数就会被循环执行


coroutine: 协程对象
可以将携 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/requests%20Code%20Cookie/" title="2. requests 验证码识别和Cookie"><img class="post-bg" src= "" data-lazy-src="https://www.cnlogo8.com/d/file/20210809/x33ajnaamczcnlogo8.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="2. requests 验证码识别和Cookie"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/requests%20Code%20Cookie/" title="2. requests 验证码识别和Cookie">2. requests 验证码识别和Cookie</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T07:54:25.000Z" title="发表于 2023-04-10 15:54:25">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/requests/">requests</a></span></div><div class="content">识别验证码
人工识别
第三方自动识别
云打码: http://www.yudama.com/demo.html



模拟登陆流程的简单例子123456789101112131415# 根据登陆请求的formdata# 验证码需要识别传入data = &#123;	&#x27;username&#x27;:username,	&#x27;password&#x27;:password,	&#x27;captcha&#x27;: captcha,	# ...&#125;response = requests.post(url=url, headers=headers, data=data)# 检验是否请求成功print(response.status_code)# 传回来的数据login_page_text = response.textwith open(&#x27;1.html&#x27;, &#x27;w&#x27;, encoding=&quot;utf-8&quot;) as f:	f.write(login_page_text)

模拟cookie操作登陆之后,请求别的页面, ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/xpath/" title="1.2 xpath简单介绍"><img class="post-bg" src= "" data-lazy-src="https://www.w3cschool.cn/attachments/image/20161103/1478161528585228.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="1.2 xpath简单介绍"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/xpath/" title="1.2 xpath简单介绍">1.2 xpath简单介绍</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T07:54:23.000Z" title="发表于 2023-04-10 15:54:23">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/">自动化</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%BD%91%E9%A1%B5%E8%A7%A3%E6%9E%90/">网页解析</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/xpath/">xpath</a></span></div><div class="content">xpath解析: 最常用且便捷高效的一种解析方式
使用快捷方法：打开F12，右键点击html节点复制xpath

xpath解析原理:1. 实例化一个etree对象,将要解析的页面元am加载到该对象中
2. 调用etree对象中的xpath方法,结合xpath表达式实现标签定位和内容捕获

流程
安装 pip install lxml
导入 from lxml import etree
实例化etree对象:
将本地的html文档中的源码加载到etree对象中:  tree = etree.parse(filePath)
将网络中获取的源码加载到etree中  tree = etree.HTML(&#39;page text&#39;)



xpath表达式res = tree.xpath(xpath表达式)

/:表示从根节点开始定位,代表一个层级 例,定位title: /html/head/title

//:表示多层级,可以从任意位置开始定位 例,定位title: //title

属性定位: 根据一个标签的属性来定位,tag[@attrName=&quot;attrValue ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/10/python%E6%89%93%E5%8C%85/" title="python pyinstaller打包"><img class="post-bg" src= "" data-lazy-src="https://img.php.cn/upload/article/000/000/034/5cdd0a4528883299.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python pyinstaller打包"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/10/python%E6%89%93%E5%8C%85/" title="python pyinstaller打包">python pyinstaller打包</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2023-04-10T07:52:13.000Z" title="发表于 2023-04-10 15:52:13">2023-04-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a></span></div><div class="content">安装pip install pyinstaller
配置文件
通常pip安装会失败

whl安装
https://www.lfd.uci.edu/~gohlke/pythonlibs/下载whl
pip install xxx.whl官网下载
去pyisntaller官网下载http://www.pyinstaller.org/downloads.html
解压,进入目录,python setup.py install,顺序不要错

遇到的问题:项目引用ui,打包是会出现unable to open/read ui device解决方案(两者解决方法):

打包完成后,复制ui文件夹到打包目录,可正常读取 ********
将ui转换成py文件

pyinstaller打包命令pyinstaller index.py --workpath xxx --distpath xxx

workpath 制作过程中临时文件的存放目录(省略为index.py同级目录)
distpath 最终可执行文件目录所在的父目录(省略为index.py同级目录)
打包完成运行可执行文件,运行出现 could ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2022/01/10/Beautifulsoup4/" title="1.1 BeautifulSoup简单介绍"><img class="post-bg" src= "" data-lazy-src="https://pic1.zhimg.com/v2-a4c6b2b3504284423e625419eef9760c_r.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="1.1 BeautifulSoup简单介绍"></a></div><div class="recent-post-info"><a class="article-title" href="/2022/01/10/Beautifulsoup4/" title="1.1 BeautifulSoup简单介绍">1.1 BeautifulSoup简单介绍</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2022-01-10T07:53:23.000Z" title="发表于 2022-01-10 15:53:23">2022-01-10</time></span><span class="article-meta tags"><span class="article-meta-separator">|</span><i class="fas fa-tag"></i><a class="article-meta__tags" href="/tags/python/">python</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/BeautifulSoup/">BeautifulSoup</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/">自动化</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%88%AC%E8%99%AB/">爬虫</a><span class="article-meta-link">•</span><a class="article-meta__tags" href="/tags/%E7%BD%91%E9%A1%B5%E8%A7%A3%E6%9E%90/">网页解析</a></span></div><div class="content">更为详细的教程建议看崔庆才得博客https://cuiqingcai.com/1319.htmlBeautifulSoup安装12pip install bs4pip install lxml
引入from bs4 import BeautifulSoup
加载网页123456# 1. 本地page_text = open(&#x27;1.txt&#x27;, &#x27;r&#x27;, encoding=&quot;utf-8&quot;)# 2. 网络page_text = request.get(url).text# 相同的，这点和xpath不同soup = BeautifulSoup(page_text, &#x27;lxml&#x27;)

数据解析方法和属性
标签定位
123456soup.a 						    # 定位的是第一次出现的tagName标签soup.find(&#x27;div&#x27;) 	            # 第一个div 等同于 soup.divsoup.find(&#x27;div&#x27;, class_=&#x27;test&#x27 ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/page/2/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/#content-inner">2</a><span class="page-number current">3</span></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/logo.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">梧桐影下月光卧</div><div class="author-info__description">分享个人学习路上的小知识</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">28</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://beau.acwy.fun"><i class="fa-solid fa-envelope"></i><span>点击联系我</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><b> <font color="#e66b6d">欢</font> <font color="#e66d98">迎</font> <font color="#e66cc6">访</font> <font color="#cc6de6">问</font> <font color="#9770e6">a</font> <font color="#6d93e6">c</font> <font color="#6fcde6">w</font> <font color="#72e6b6">y</font> <font color="#72e689">的</font> <font color="#99e670">学</font> <font color="#cde670">习</font> <font color="#e6df72">日</font> <font color="#e6c073">记</font> </b> <p align="center"> <img src= "" data-lazy-src="https://upyun.acwy.fun/acwy.fun/公告1.gif" width="50" alt="mao"> </p> <p align="center">微信：acwy0718</p> <p align="center">邮箱：awy0718@gmail.com</p></div></div><div class="sticky_layout"><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/%E8%81%94%E7%B3%BB%E6%88%91/" style="font-size: 1.15em; color: rgb(12, 167, 197)">联系我</a><a href="/tags/hexo/" style="font-size: 1.33em; color: rgb(76, 64, 106)">hexo</a><a href="/tags/hexo-Butterfly-%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2/" style="font-size: 1.27em; color: rgb(58, 153, 126)">hexo-Butterfly - 静态博客</a><a href="/tags/python/" style="font-size: 1.45em; color: rgb(41, 128, 28)">python</a><a href="/tags/BeautifulSoup/" style="font-size: 1.15em; color: rgb(143, 60, 188)">BeautifulSoup</a><a href="/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 1.27em; color: rgb(186, 155, 148)">自动化</a><a href="/tags/%E7%88%AC%E8%99%AB/" style="font-size: 1.39em; color: rgb(168, 76, 168)">爬虫</a><a href="/tags/%E7%BD%91%E9%A1%B5%E8%A7%A3%E6%9E%90/" style="font-size: 1.21em; color: rgb(75, 41, 146)">网页解析</a><a href="/tags/playwright/" style="font-size: 1.21em; color: rgb(64, 194, 40)">playwright</a><a href="/tags/%E9%9D%99%E6%80%81%E5%8D%9A%E5%AE%A2/" style="font-size: 1.15em; color: rgb(87, 94, 5)">静态博客</a><a href="/tags/requests/" style="font-size: 1.15em; color: rgb(71, 79, 194)">requests</a><a href="/tags/win10/" style="font-size: 1.21em; color: rgb(12, 191, 47)">win10</a><a href="/tags/%E5%8F%B3%E9%94%AE%E6%B7%BB%E5%8A%A0cmd/" style="font-size: 1.15em; color: rgb(115, 66, 77)">右键添加cmd</a><a href="/tags/windows%E7%B3%BB%E7%BB%9F/" style="font-size: 1.15em; color: rgb(166, 103, 135)">windows系统</a><a href="/tags/%E5%AE%89%E5%8D%93/" style="font-size: 1.15em; color: rgb(107, 113, 120)">安卓</a><a href="/tags/xpath/" style="font-size: 1.15em; color: rgb(40, 122, 102)">xpath</a><a href="/tags/node/" style="font-size: 1.15em; color: rgb(66, 39, 20)">node</a><a href="/tags/npm/" style="font-size: 1.15em; color: rgb(58, 129, 175)">npm</a><a href="/tags/php/" style="font-size: 1.21em; color: rgb(194, 18, 177)">php</a><a href="/tags/%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA/" style="font-size: 1.15em; color: rgb(49, 193, 129)">虚拟主机</a><a href="/tags/%E4%B8%87%E7%BD%91/" style="font-size: 1.15em; color: rgb(141, 54, 58)">万网</a><a href="/tags/thinkphp/" style="font-size: 1.15em; color: rgb(147, 192, 15)">thinkphp</a><a href="/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%80%9A%E4%BF%A1/" style="font-size: 1.15em; color: rgb(18, 9, 42)">服务器通信</a><a href="/tags/%E5%89%8D%E7%AB%AF/" style="font-size: 1.15em; color: rgb(104, 35, 184)">前端</a><a href="/tags/%E5%86%B0%E7%82%B9%E8%BF%98%E5%8E%9F/" style="font-size: 1.15em; color: rgb(194, 37, 41)">冰点还原</a><a href="/tags/%E8%B7%B3%E8%BF%87%E5%B9%BF%E5%91%8A/" style="font-size: 1.15em; color: rgb(124, 196, 154)">跳过广告</a><a href="/tags/gkd/" style="font-size: 1.15em; color: rgb(15, 88, 28)">gkd</a><a href="/tags/%E6%9D%8E%E8%B7%B3%E8%B7%B3/" style="font-size: 1.15em; color: rgb(54, 150, 84)">李跳跳</a><a href="/tags/%E7%8E%A9%E5%AE%A2%E4%BA%91/" style="font-size: 1.27em; color: rgb(45, 38, 18)">玩客云</a><a href="/tags/armbian/" style="font-size: 1.21em; color: rgb(167, 27, 196)">armbian</a><a href="/tags/linux%E6%8C%82%E8%BD%BD%E7%A1%AC%E7%9B%98/" style="font-size: 1.15em; color: rgb(149, 172, 174)">linux挂载硬盘</a><a href="/tags/cloudreve/" style="font-size: 1.15em; color: rgb(4, 40, 131)">cloudreve</a><a href="/tags/%E7%B2%A4%E6%95%99%E7%89%88/" style="font-size: 1.21em; color: rgb(42, 60, 10)">粤教版</a><a href="/tags/%E7%BA%BF%E7%A8%8B/" style="font-size: 1.21em; color: rgb(31, 192, 139)">线程</a><a href="/tags/%E8%BF%9B%E7%A8%8B/" style="font-size: 1.15em; color: rgb(103, 25, 61)">进程</a></div></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">28</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2020-09-25T07:31:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">13.7k</div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2024-05-05T13:13:51.207Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/top_img.jpeg')"><div id="footer-wrap"><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><div> <a href="https://beian.miit.gov.cn/" target="_blank">豫ICP备2023010490号-1</a> </div> <div> <a style="display:flex;justify-content:center;align-items:center;" target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=41152402000204"> <img src= "" data-lazy-src="/img/beian.png" style="width:20px;height:20px;margin:0 5px"> <span>豫公网安备 41152402000204号</span> </a> </div> <div> <a style="display:flex;justify-content:center;" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" target="_blank"> <span>本网站由</span> <img style="height:30px;margin:0 3px" src= "" data-lazy-src="/img/upyun_logo5.png"> <span>提供CDN加速/云存储服务</span> </a> <div/></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"><script>window.typedJSFn = {
  init: (str) => {
    window.typed = new Typed('#subtitle', Object.assign({
      strings: str,
      startDelay: 300,
      typeSpeed: 150,
      loop: true,
      backSpeed: 50,
    }, null))
  },
  run: (subtitleType) => {
    if (true) {
      if (typeof Typed === 'function') {
        subtitleType()
      } else {
        getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
      }
    } else {
      subtitleType()
    }
  }
}
</script><script>function subtitleType () {
  fetch('https://v1.hitokoto.cn')
    .then(response => response.json())
    .then(data => {
      if (true) {
        const from = '出自 ' + data.from
        const sub = []
        sub.unshift(data.hitokoto, from)
        typedJSFn.init(sub)
      } else {
        document.getElementById('subtitle').innerHTML = data.hitokoto
      }
    })
}
typedJSFn.run(subtitleType)
</script></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/fireworks.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script></div></body></html>